

package com.maoshi.shop.seckill.multishop.controller;

import com.maoshi.shop.seckill.comment.model.SeckillOrder;
import com.maoshi.shop.seckill.comment.service.SeckillOrderService;
import com.maoshi.shop.common.annotation.SysLog;

import javax.validation.Valid;

import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import lombok.AllArgsConstructor;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.maoshi.shop.common.util.PageParam;
import com.baomidou.mybatisplus.core.metadata.IPage;


/**
 * 秒杀订单
 *
 * @author LGH
 * @date 2019-08-28 09:36:59
 */
@RestController
@AllArgsConstructor
@RequestMapping("/seckill/seckillOrder" )
public class SeckillOrderController {

    private final SeckillOrderService seckillOrderService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param seckillOrder 秒杀订单
     * @return 分页数据
     */
    @GetMapping("/page" )
    public ResponseEntity<IPage<SeckillOrder>> getSeckillOrderPage(PageParam<SeckillOrder> page, SeckillOrder seckillOrder) {
        return ResponseEntity.ok(seckillOrderService.page(page, new LambdaQueryWrapper<SeckillOrder>()));
    }


    /**
     * 通过id查询秒杀订单
     * @param seckillOrderId id
     * @return 单个数据
     */
    @GetMapping("/info/{seckillOrderId}" )
    public ResponseEntity<SeckillOrder> getById(@PathVariable("seckillOrderId") Long seckillOrderId) {
        return ResponseEntity.ok(seckillOrderService.getById(seckillOrderId));
    }

    /**
     * 新增秒杀订单
     * @param seckillOrder 秒杀订单
     * @return 是否新增成功
     */
    @SysLog("新增秒杀订单" )
    @PostMapping
    public ResponseEntity<Boolean> save(@RequestBody @Valid SeckillOrder seckillOrder) {
        return ResponseEntity.ok(seckillOrderService.save(seckillOrder));
    }

    /**
     * 修改秒杀订单
     * @param seckillOrder 秒杀订单
     * @return 是否修改成功
     */
    @SysLog("修改秒杀订单" )
    @PutMapping
    public ResponseEntity<Boolean> updateById(@RequestBody @Valid SeckillOrder seckillOrder) {
        return ResponseEntity.ok(seckillOrderService.updateById(seckillOrder));
    }

    /**
     * 通过id删除秒杀订单
     * @param seckillOrderId id
     * @return 是否删除成功
     */
    @SysLog("删除秒杀订单" )
    @DeleteMapping("/{seckillOrderId}" )
    public ResponseEntity<Boolean> removeById(@PathVariable Long seckillOrderId) {
        return ResponseEntity.ok(seckillOrderService.removeById(seckillOrderId));
    }

}
